package com.awakening.code.servlet;


import com.awakening.code.bean.Message;
import com.awakening.code.service.ListService;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.ArrayList;
import java.util.List;

/**
 * 列表页面初始化控制
 * 一般情况下Servlet层是不直接调用Dao的
 * @Author:这个程序员有纹身
 * @Date: Created in 10:10 2018\1\11 0011
 */
public class ListServlet extends HttpServlet{

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp)
            throws ServletException, IOException {
        //设置上传格式
        req.setCharacterEncoding("UTF-8");
        //获取上传值
        String command = req.getParameter("command");
        String description = req.getParameter("description");
        //查询后，前端页面值保留
        req.setAttribute("command",command);
        req.setAttribute("description",description);
        try {
            //查询消息列表并传给页面
            ListService listService = new ListService();
            req.setAttribute("messageList",listService.findList(command,description));
        }catch (Exception e){
            System.out.println(e.getMessage());
        }
        //向页面跳转
        req.getRequestDispatcher("/WEB-INF/jsp/back/list.jsp").forward(req,resp);
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp)
            throws ServletException, IOException {
        this.doGet(req, resp);
    }
}
